<!DOCTYPE html>

<html xmlns:th="http://www.thymeleaf.org">

<head>

    <meta charset="UTF-8">
    <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0" />
    <title></title>
    <script src="../js/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="../mycss/main.css"/>
    <link rel="stylesheet" href="../bootstrap-3.3.7-dist/css/bootstrap.css" media="screen"/>
    <div th:include="header :: header"/>
    <script th:inline="javascript">

    // 发送开锁请求
    function openLock(lockId) {
        alert("尝试开锁?");
        var getSecureDataUrl = "http://58.87.74.194:8029/securedata?openLockId=" + lockId;
        var url = "http://119.29.242.75:9999/lockManager";
        alert(getSecureDataUrl);
        $.post(getSecureDataUrl,{}, 
        		function(data) {
                    if (data === null) {}
                    else {
                    	$.post(url,
                    			{
                                 "secureData":data
                                }, 
                                function(retData){
                               alert(retData);
                               }
                        );
                    }
            }	
        );
       
    }
    
    
 // 去我的主页
    function home() {
        var userId = [[${userId}]];
        var url = "http://111.230.107.192:8082/home" + "?userId=" + userId;
        window.location.href = url;
    }
    </script>
</head>

<body>

<table class="table table-striped">
<div>
<button type="button" class="btn btn-default btn-info" onclick="home()">返回主页</button>
</div>
<br/>
<div>

    
        <tr>
        <div>
        <th>房间ID</th>
        <th>看房时间</th>
        <th>看房时长(小时)</th>
        <th>状态</th>
        <th>按钮</th>
        </div>
        </tr>
    
   
       
        <tr th:each="room:${rooms}">
        <td th:if="${room}" th:text="${room.roomId}"></td>
        <td th:if="${room}" th:text="${room.date}"></td>
        <td th:text="${room.duration}"></td>
        <td th:if="${room.status}">有效</td>
        <td th:if="${not room.status}">无效</td>
        <td th:if="${room.status}"><button th:onclick="'openLock(\''+${room.openLockId}+'\')'">开锁</button></td>
        <td th:if="${not room.status}"><button disabled="disabled" style="color:#999">开锁</button></td>
        </tr>

</div>
</table>
</body>

</html>